package com.beuth.taskList.activities.tools;

import java.util.Collections;
import java.util.Comparator;
import java.util.GregorianCalendar;

import android.util.Log;

import com.beuth.taskList.model.SortType;
import com.beuth.taskList.model.Task;

public class TaskComperator implements Comparator<Task> {
	
	SortType sortType = SortType.TIMELEFT_ASC;
	
	public TaskComperator(SortType sortType) {
		this.sortType = sortType;
	}
	
    @Override
    public int compare(Task o1, Task o2) {
    	switch (sortType) {
		case NAME_ASC : return sortByNameAsc(o1, o2);
		case NAME_DEC : return sortByNameDec(o1, o2);
		case PRIORITY_ASC : return sortByPriorityAsc(o1, o2);
		case PRIORITY_DEC : return sortByPriorityDec(o1, o2);
		case TASKTYPE_ASC : return sortByTaskTypeAsc(o1, o2);
		case TASKTYPE_DEC : return sortByTaskTypeDec(o1, o2);
		case CLOSINGDATE_ASC : return sortByClosingDateAsc(o1, o2);
		case CLOSINGDATE_DEC : return sortByClosingDateDec(o1, o2);
		/*case PERCENT_ASC : return sortByPercentAsc(o1, o2);
		case PERCENT_DEC : return sortByPercentDec(o1, o2);
		case TIMESPEND_ASC : return sortByTimeSpendAsc(o1, o2);
		case TIMESPEND_DEC : return sortByTimeSpendDec(o1, o2);*/
		case TIMELEFT_ASC : return sortByTimeLeftAsc(o1, o2);
		case TIMELEFT_DEC : return sortByTimeLeftDec(o1, o2);
		default:
			break;
		}
    	
        return o1.getName().compareTo(o2.getName());
    }
    
	private int sortByNameAsc(Task o1, Task o2) {
		return o1.getName().compareTo(o2.getName());
	}
	
	private int sortByNameDec(Task o1, Task o2) {
		return o2.getName().compareTo(o1.getName());
	}
	
	private int sortByPriorityAsc(Task o1, Task o2) {
		return o1.getPriority().compareTo(o2.getPriority());
	}
	
	private int sortByPriorityDec(Task o1, Task o2) {
		return o2.getPriority().compareTo(o1.getPriority());
	}
	
	private int sortByTaskTypeAsc(Task o1, Task o2) {
		return o1.getTaskType().toString().compareTo(o2.getTaskType().toString());
	}
	
	private int sortByTaskTypeDec(Task o1, Task o2) {
		return o2.getTaskType().toString().compareTo(o1.getTaskType().toString());
	}
	
	private int sortByClosingDateAsc(Task o1, Task o2) {
		return o1.getClosingDate().compareTo(o2.getClosingDate());
	}
	
	private int sortByClosingDateDec(Task o1, Task o2) {
		return o2.getClosingDate().compareTo(o1.getClosingDate());
	}
	
	private int sortByPercentAsc(Task o1, Task o2) {
		return 0;
	}
	
	private int sortByPercentDec(Task o1, Task o2) {
		return 0;
	}
	
	private int sortByTimeSpendAsc(Task o1, Task o2) {
		return 0;
	}
	
	private int sortByTimeSpendDec(Task o1, Task o2) {
		return 0;
	}
	
	private int sortByTimeLeftAsc(Task o1, Task o2) {
		return o1.getClosingDate().compareTo(o2.getClosingDate());
	}
	
	private int sortByTimeLeftDec(Task o1, Task o2) {
		return o2.getClosingDate().compareTo(o1.getClosingDate());
	}
	
}
